package com.hiv.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {

  @Override
  public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
        .allowedHeaders("Content-Type","X-Requested-With","accept,Origin","Access-Control-Request-Method","Access-Control-Request-Headers","token")
        .allowedMethods("*")
        .allowedOrigins("*")
        .allowCredentials(true);
  }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    /** 本地文件上传路径 */
    String path = ConfigurationConfig.applicationUploadPath + File.separator + ConfigurationConfig.applicationName + File.separator;
    System.out.println("path=" + path);
    registry.addResourceHandler("/profile/**").addResourceLocations("file:" + path);
  }

}
